local bifeng = fk.CreateSkill{
    name = "jinhs__bifeng",
}

Fk:loadTranslationTable{
    ["jinhs__bifeng"] = "避锋",
    [":jinhs__bifeng"] = "你可以将一张应变牌当带有相同应变效果的【杀】或【闪】使用或打出；"..
    "当你使用或打出牌响应颜色相同的牌后，你可以获得被响应的牌。",

    ["#jinhs__bifeng"] = "避锋：你可以将一张应变牌当带有相同应变效果的【杀】或【闪】使用或打出；",

    ["$jinhs__bifeng1"] = "彼美齐献，卓尔不群。",
    ["$jinhs__bifeng2"] = "扶风遗爱，琅邪克己。",
}

bifeng:addEffect("viewas",{
    anim_type = "special",
    pattern = "slash,jink",
    prompt = "#jinhs__bifeng",
    handly_pile = true,
    interaction = function(self, player)
      local all_names = {"slash","jink"}
      local names = player:getViewAsCardNames(bifeng.name, all_names)
      if #names > 0 then
        return UI.CardNameBox { choices = names, all_choices = all_names }
      end
    end,
    card_filter = function(self, player, to_select, selected)
      local card = Fk:getCardById(to_select)
      return #selected == 0 and table.contains(player:getHandlyIds(), to_select) and card.extra_data and card.extra_data.heg_variation
      and card:getMark(card.extra_data.heg_variation[1])
    end,
    before_use = function(self, player, use)
        local card = Fk:getCardById(use.card.subcards[1])
        if table.find({"@fujia-public", "@kongchao-public", "@canqu-public", "@zhuzhan-public", "@heg_yibing-public"}, function(mark)
          return card.extra_data and card.extra_data.heg_variation and card.extra_data.heg_variation[1] == mark end) then
          use.card.extra_data = use.card.extra_data or {}
          use.card.extra_data.heg_variation = card.extra_data.heg_variation
      end
    end,
    view_as = function(self, player, cards)
      if #cards ~= 1 or not self.interaction.data then return end
      local card = Fk:cloneCard(self.interaction.data)
      card:addSubcard(cards[1])
      card.skillName = bifeng.name
      return card
    end,
})

bifeng:addEffect(fk.CardUseFinished,{
    anim_type = "defensive",
    can_trigger = function (self, event, target, player, data)
       return target == player and player:hasSkill(bifeng.name) and data.responseToEvent and data.card.color == data.responseToEvent.card.color
       and data.responseToEvent.to == player
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if player.dead then return end
        room:moveCardTo(data.responseToEvent.card, Player.Hand, player, fk.ReasonJustMove, bifeng.name, nil, true, player)
    end,
})

bifeng:addEffect(fk.CardRespondFinished,{
    anim_type = "defensive",
    can_trigger = function (self, event, target, player, data)
       return target == player and player:hasSkill(bifeng.name) and data.responseToEvent and data.card.color == data.responseToEvent.card.color
       and data.responseToEvent.to == player
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if player.dead then return end
        room:moveCardTo(data.responseToEvent.card, Player.Hand, player, fk.ReasonJustMove, bifeng.name, nil, true, player)
    end,
})


return bifeng